// 这里放的是一个counter
import { createSlice } from "@reduxjs/toolkit";

const counterStore = createSlice({
  name: "counter",
  initialState: {
    count: 0,
  },
  // 修改状态的方法
  reducers: {
    // 新增
    inscrement(state) {
      state.count++;
    },
    // 减少
    decrement(state,action) {
      // if(action.payload){
      //   state.count=action.payload;
      // }else{
        state.count--;
      // }
 
    },
    addToNum(state,action){
      state.count=action.payload;
    }
  },
});

// 解构出来actionCreater函数

const {inscrement,decrement,addToNum} =counterStore.actions

// 获取reducer
const reducer=counterStore.reducer

// 导出inscrement和decrement
export {inscrement,decrement,addToNum}
export default reducer